package io.renren.imooc.socket;

import com.xiaoleilu.hutool.io.IoUtil;

import java.io.*;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * Created by kun on 2017/5/2.
 */
public class Server {

    public static void main(String args[]){
        try {
            //创建
            ServerSocket serverSocket=new ServerSocket(8888);
            //调用accepet()等待客户端连接
            System.out.println("服务器已启动,等待客户端连接");
            Socket socket=null;
            int count=0;
            while (true){
                socket = serverSocket.accept();
                ServerThread serverThread=new ServerThread(socket);
                serverThread.start();

                count++;
                System.out.println("客户端数量"+count);
                InetAddress address=socket.getInetAddress();
                System.out.println("当前客户端IP:"+address.getHostAddress());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
